# !/usr/bin/env python
# -*-coding:utf-8 -*-

"""
# File       : __init__.py.py
# Time       ：2023/10/28 21:59
# Author     ：Y-aong
# version    ：python 3.10
# Description：
"""
from marshmallow import fields
from marshmallow_sqlalchemy import SQLAlchemyAutoSchema

from orderlines.utils.utils import get_variable_value


class PluginNodeInfoSchema(SQLAlchemyAutoSchema):
    type = fields.Function(serialize=lambda obj: obj.node_type)
    title = fields.Function(serialize=lambda obj: obj.title)
    background = fields.String()
    category = fields.String()
    icon = fields.String()
    class_name = fields.String()
    text = fields.Function(serialize=lambda obj: obj.method_desc)
    method_name = fields.String()
    version = fields.String()


class ProcessVersionSchema(SQLAlchemyAutoSchema):
    id = fields.Integer()
    process_id = fields.String()
    process_name = fields.String()
    version = fields.String()
    version_desc = fields.String()


class SubProcessParamsSchema(SQLAlchemyAutoSchema):
    process_id = fields.String()
    variable_key = fields.String()
    variable_value = fields.Function(
        serialize=lambda obj: get_variable_value(obj.variable_value, obj.variable_type)
    )
    variable_type = fields.String()
    variable_desc = fields.String()


class DefaultTaskConfigSchema(SQLAlchemyAutoSchema):
    config_name = fields.String()
    config_value = fields.String()
    desc = fields.String()
